import {
  Entity,
  Column,
  PrimaryGeneratedColumn,
  // 自增
  CreateDateColumn,
} from 'typeorm';
import { ApiProperty } from '@nestjs/swagger';
import {
  ColumnStatus,
  YixiantongFieldItem,
} from './yixiantong.type';

@Entity()
export class YixiantongFieldsGoods {
  @PrimaryGeneratedColumn({
    type: 'bigint',
    comment: '主键索引 id',
    name: 'id',
  })
  @ApiProperty({ description: '主键索引 id' })
  public id: number;

  @Column({
    name: 'field',
    comment: '一线通条目 - 类型',
    nullable: false, // 非空
  })
  @ApiProperty({ description: '一线通条目 - 类型' })
  public field: YixiantongFieldItem | string;

  @Column({
    comment: '一线通条目 - 名称',
    nullable: false, // 非空
  })
  @ApiProperty({ description: '一线通条目 - 名称' })
  public name: string;

  @Column({
    comment: '一线通条目 - 价格',
    type: 'double',
    nullable: true, // 可为空
    default: 0,
  })
  @ApiProperty({ description: '一线通条目 - 价格' })
  public price: number;

  @Column({
    comment: '地址',
    nullable: true, // 可为空
    default: '',
  })
  @ApiProperty({ description: '地址' })
  public address: string;

  @Column({
    comment: '星评',
    nullable: true, // 可为空
  })
  @ApiProperty({ description: '星评' })
  public star: number;

  @Column({
    comment: '评分',
    nullable: true, // 可为空
  })
  @ApiProperty({ description: '评分' })
  public score: number;

  @Column({
    comment: '最低价格（默认摘取）',
    nullable: true, // 可为空
    name: 'default_price',
  })
  @ApiProperty({ description: '最低价格（默认摘取）' })
  public defaultPrice: number;

  @Column({
    type: 'varchar',
    comment: '城市名称 (对应另外一张表的枚举值)',
    nullable: false, // 非空
    name: 'city_name',
  })
  @ApiProperty({ description: '城市名称 (对应另外一张表的枚举值)' })
  public cityName: string;

  @CreateDateColumn({
    comment: '创建时间',
    name: 'create_time',
    type: 'datetime',
    nullable: false, // 非空
    default: null // 设置默认值为当前时间戳
  })
  @ApiProperty({ description: '创建时间' })
  public createTime: Date;

  @CreateDateColumn({
    comment: '更新时间',
    name: 'update_time',
    type: 'datetime',
    nullable: false, // 非空
    default: null // 设置默认值为当前时间戳
  })
  @ApiProperty({ description: '更新时间' })
  public updateTime: Date;

  @Column({
    comment: '推荐条目',
    name: 'recom_items',
    nullable: true,
    type: 'text'
  })
  @ApiProperty({ description: '推荐条目' })
  public recom: string;

  @Column({
    comment: '关键词 (字符串, 多个用英文逗号隔开)',
    type: 'text',
    nullable: true,
    name: 'keywords'
  })
  @ApiProperty({ description: '关键词 (字符串, 多个用英文逗号隔开)' })
  public keywords: string;

  @Column({
    comment: '简介',
    type: 'text',
    name: 'description',
  })
  @ApiProperty({ description: '简介' })
  public description: string;

  @Column({
    comment: '购票信息',
    type: 'text',
    name: 'ticket_info',
    nullable: true,
  })
  @ApiProperty({ description: '购票信息' })
  public ticketInfo: string;

  @Column({
    comment: '预览图片',
    name: 'preview_img',
    type: 'text', // 文本类型
    nullable: true, // 可为空
  })
  @ApiProperty({ description: '预览图片' })
  public img: string;

  @Column({
    comment: '图片集',
    type: 'json',
    name: 'banners',
    default: null,
    nullable: true,
  })
  @ApiProperty({ description: '图片集' })
  banners: string[];

  @Column({
    comment: '状态',
    default: ColumnStatus.Normal,
  })
  @ApiProperty({ description: '状态' })
  public status: ColumnStatus;

  setBanners(banners: string[]) {
    this.banners = banners;
  }
}